package com.cskaoyan.service.impl;

import com.cskaoyan.bean.pojo.MallGoodsExample;
import com.cskaoyan.bean.pojo.MallGoodsProductExample;
import com.cskaoyan.bean.pojo.MallOrderExample;
import com.cskaoyan.bean.pojo.MallUserExample;
import com.cskaoyan.bean.vo.DashboardVO;
import com.cskaoyan.mapper.MallGoodsMapper;
import com.cskaoyan.mapper.MallGoodsProductMapper;
import com.cskaoyan.mapper.MallOrderMapper;
import com.cskaoyan.mapper.MallUserMapper;
import com.cskaoyan.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: zoey-zhu
 * @description: 首页(GET)
 * @Date: 20:37 2021/7/8
 */
@Service
public class DashboardServiceImpl implements DashboardService {

    @Autowired
    MallGoodsMapper mallGoodsMapper;

    @Autowired
    MallUserMapper mallUserMapper;

    @Autowired
    MallGoodsProductMapper mallGoodsProductMapper;

    @Autowired
    MallOrderMapper mallOrderMapper;

    /**
     * @Author: zoey-zhu
     * @description: 首页(GET)：查询订单、用户、货品、订单的数量
     * @Date 20:27 2021/7/8
     * url: http://localhost:8083/admin/dashboard
     */
    public DashboardVO dashboard(){

        //查询订单的数量
        MallGoodsExample mallGoodsExample = new MallGoodsExample();
        MallGoodsExample.Criteria criteria = mallGoodsExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        long goodsTotal = mallGoodsMapper.countByExample(mallGoodsExample);

        //查询用户的数量
        MallUserExample mallUserExample = new MallUserExample();
        MallUserExample.Criteria criteria1 = mallUserExample.createCriteria();
        criteria1.andDeletedEqualTo(false);
        long userTotal = mallUserMapper.countByExample(mallUserExample);

        //查询货品的数量
        MallGoodsProductExample mallGoodsProductExample = new MallGoodsProductExample();
        MallGoodsProductExample.Criteria criteria2 = mallGoodsProductExample.createCriteria();
        criteria2.andDeletedEqualTo(false);
        long productTotal = mallGoodsProductMapper.countByExample(mallGoodsProductExample);

        //查询订单的数量
        MallOrderExample mallOrderExample = new MallOrderExample();
        MallOrderExample.Criteria criteria3 = mallOrderExample.createCriteria();
        criteria3.andDeletedEqualTo(false);
        long orderTotal = mallOrderMapper.countByExample(mallOrderExample);

        //封装
        DashboardVO dashboardVO = new DashboardVO(goodsTotal, userTotal, productTotal, orderTotal);

        return dashboardVO;
    }

}
